package com.twetec.cms.adapter.pc.backend.controller.website;

import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.twetec.cms.adapter.pc.backend.exception.StaticHtmlException;
import com.twetec.cms.adapter.pc.backend.response.R;
import com.twetec.cms.adapter.pc.backend.response.ResultCodeMsgEnum;
import com.twetec.cms.adapter.pc.backend.util.beetl.html.BeetlStaticHtml;
import com.twetec.cms.common.constant.*;
import com.twetec.cms.common.util.validate.ValidateUtil;
import com.twetec.cms.model.po.system.StaticLogPO;
import com.twetec.cms.model.po.website.*;
import com.twetec.cms.service.system.StaticLogService;
import com.twetec.cms.service.website.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 站点栏目
 */
@Api(tags = "站点静态化模块")
@RestController
@RequestMapping("/website/static-html")
public class StaticHtmlController {

    @Autowired
    ArticleService articleService;

    @Autowired
    private SiteService siteService;

    @Autowired
    private SiteColumnService siteColumnService;

    @Autowired
    private ColumnService columnService;

    @Autowired
    private BeetlStaticHtml beetlStaticHtml;


    @Value("${twetec.resource.storage-root-path}")
    private String rootPath;

    // 站点的pc端模板文件存储路径,从数据库中查出来的
    private String pcSiteTemplatePath;

    // 站点的h5端模板文件存储路径,从数据库中查出来的
    private String h5SiteTemplatePath;


    @Autowired
    private ColumnArticleModelService columnArticleModelService;

    @Autowired
    private ArticleExtendService extendService;

    @Autowired
    private StaticLogService staticLogService;

    /**
     * 静态化错误信息
     */
    private Map<String, String> errorMessageMap;


    @ApiOperation(value = "全站静态化")
    @GetMapping("/site-to-static-html")
    public R siteToStaticHtml(@ApiParam(value = "站点id", required = true, example = "123456789") @RequestParam(required = false) Long siteId) {
        // 接收参数
        if (siteId == null || !ValidateUtil.Number(siteId) || siteId <= 0)
            return R.failureRequestParam().msg("站点id不能为空");

        // 查询站点信息
        SitePO sitePO = siteService.getById(siteId);
        if (ValidateUtil.isNullOrEmpty(sitePO)) return R.resultCodeMsg(ResultCodeMsgEnum.DATA_NOT_EXIST);

        QueryWrapper<StaticLogPO> staticLogPOQueryWrapper = new QueryWrapper<>();
        staticLogPOQueryWrapper.eq("SITE_ID", siteId);
        staticLogPOQueryWrapper.eq("STATUS", StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        staticLogPOQueryWrapper.eq("STATIC_TYPE", StaticHtmlTypeEnum.ALL.getValue());
        StaticLogPO staticLogPO = staticLogService.getOne(staticLogPOQueryWrapper, false);
        if (null != staticLogPO && null != staticLogPO.getId()) {
            return R.failure().msg("静态化任务正在进行,请稍后再试!");
        }

        // 将静态化日志设置为进行中
        StaticLogPO logPO = new StaticLogPO();
        logPO.setSiteId(siteId);
        // 进行中
        logPO.setStatus(StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        // 全站
        logPO.setStaticType(StaticHtmlTypeEnum.ALL.getValue());
        boolean save = staticLogService.save(logPO);

        // 生成站点首页
        Boolean siteResult = p_staticIndexToStatic(sitePO);
        if (!siteResult) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            return R.failure().msg(this.errorMessageMap.get("msg"));
        }

        // 生成栏目页以及文章页 (查询出一级栏目)
        // 首先从中间表中查出站点对应的顶级栏目ID
        QueryWrapper<SiteColumnPO> siteColumnPOQueryWrapper = new QueryWrapper<>();
        siteColumnPOQueryWrapper.eq("SITE_ID", sitePO.getId());
        List<SiteColumnPO> list = siteColumnService.list(siteColumnPOQueryWrapper);
        ArrayList<Long> columnIdList = new ArrayList<>();
        // 如果没有站点对应的栏目信息，就直接返回
        if (ValidateUtil.isNullOrEmpty(list)) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            throw new StaticHtmlException(StaticHtmlExceptionEnum.NO_COLUMN);
        } else {
            // 有对应的顶级栏目信息就获取栏目id
            for (SiteColumnPO siteColumnPO : list) {
                columnIdList.add(siteColumnPO.getColumnId());
            }
        }

        // 站点下的顶级栏目，且类型是列表、分页列表、频道封面的栏目，获取PC端的模板路径
        QueryWrapper<ColumnPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("ID", columnIdList);
        queryWrapper.eq("IS_RECOVERY", 0);
        queryWrapper.orderByDesc("SORT");
        queryWrapper.orderByAsc("ID");
        List<ColumnPO> columnPOList = columnService.list(queryWrapper);
        // 如果栏目集合为空，直接返回
        if (ValidateUtil.isNullOrEmpty(columnPOList)) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            throw new StaticHtmlException(StaticHtmlExceptionEnum.NO_COLUMN);
        }

        // 如果不为空就要准备生成--------站点的静态文件存储路径
        String storageStaticPath = siteService.getStorageStaticPath(sitePO.getId());
        // 静态文件存储路径-----到pc
        String pcStorageStaticPath = storageStaticPath + File.separator + "pc";
        String h5StorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "h5";
        boolean result = false;
        for (ColumnPO columnPO : columnPOList) {
            // 递归生成栏目页和文章页面
            result = p_generateColumnAndArticleStaticHtml(columnPO, sitePO, pcStorageStaticPath, h5StorageStaticPath);
        }

        if (!result) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            return R.failure().msg("静态化栏目页和文章页失败");
        }

        // 拷贝站点的资源文件到静态文件路径中
        boolean storage = this.p_copyResources(sitePO, storageStaticPath);

        if (!storage) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            return R.failure().msg("静态资源拷贝失败");
        }

        // 如果前面的操作成功，则生成完成以后将日志信息设置为完成
        if (save) {
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.YI_WAN_CHENG.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
        }
        return R.success().msg("静态化站点成功");
    }

    /**
     * 站点资源拷贝
     *
     * @param sitePO            站点信息
     * @param storageStaticPath 站点的静态文件存储路径---未区分模板类型的
     * @return
     */
    boolean p_copyResources(SitePO sitePO, String storageStaticPath) {

        // 如果站点模板路径为空就赋值
        if (null == pcSiteTemplatePath) {
            // 首先从中间表中查出站点对应的顶级栏目ID
            QueryWrapper<SiteColumnPO> siteColumnPOQueryWrapper = new QueryWrapper<>();
            siteColumnPOQueryWrapper.eq("SITE_ID", sitePO.getId());
            List<SiteColumnPO> list = siteColumnService.list(siteColumnPOQueryWrapper);
            ArrayList<Long> columnIdList = new ArrayList<>();
            if (!ValidateUtil.isNullOrEmpty(list)) {
                for (SiteColumnPO siteColumnPO : list) {
                    columnIdList.add(siteColumnPO.getColumnId());
                }
            } else {
                // 栏目不存在
                throw new StaticHtmlException(StaticHtmlExceptionEnum.NO_COLUMN);
            }

            // 站点下的顶级栏目，且类型是站点首页的栏目，获取PC端的模板路径
            QueryWrapper<ColumnPO> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("ID", columnIdList);
            queryWrapper.eq("IS_RECOVERY", 0);
            queryWrapper.eq("TYPE", ColumnEnum.SITE_INDEX.getType());
            queryWrapper.orderByDesc("SORT");
            queryWrapper.orderByAsc("ID");
            ColumnPO columnPO = columnService.getOne(queryWrapper, false);

            String pcTemplatePath;
            if (!ValidateUtil.isNullOrEmpty(columnPO)) {
                pcTemplatePath = columnPO.getPcTemplatePath();
                pcSiteTemplatePath = pcTemplatePath;
                if (null != columnPO.getH5TemplatePath()) {
                    h5SiteTemplatePath = columnPO.getH5TemplatePath();
                }
            } else {
                throw new StaticHtmlException(StaticHtmlExceptionEnum.NO_COLUMN);
            }
        }

        // 获取模板下的资源路径
        // 去掉后面的***.html
        String pcTemplateResourcePath = pcSiteTemplatePath.substring(0, pcSiteTemplatePath.lastIndexOf("/"));
        // 在前面拼接上根路径，后面拼接上static（资源文件夹）
        pcTemplateResourcePath = rootPath + pcTemplateResourcePath + File.separator + "static";

        String h5TemplateResourcePath = null;
        if (null != h5SiteTemplatePath) {
            h5TemplateResourcePath = h5SiteTemplatePath.substring(0, h5SiteTemplatePath.lastIndexOf("/"));
            h5TemplateResourcePath = rootPath + h5TemplateResourcePath + File.separator + "static";
        }


        // 资源拷贝路径
        File pcSourceFile = FileUtil.file(pcTemplateResourcePath);
        String pcStorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "static";
        File pcTargetFile = FileUtil.file(pcStorageStaticPath);
        FileUtil.copyContent(pcSourceFile, pcTargetFile, true);

        if (null != h5SiteTemplatePath) {
            File h5SourceFile = FileUtil.file(h5TemplateResourcePath);
            String h5StorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "h5" + File.separator + "static";
            File h5TargetFile = FileUtil.file(h5StorageStaticPath);
            FileUtil.copyContent(h5SourceFile, h5TargetFile, true);
        }

        return true;
    }

    /**
     * 递归静态化栏目页和文章页面
     *
     * @param columnPO
     * @param sitePO
     * @param parentColumnStoragePath
     * @return
     */
    boolean p_generateColumnAndArticleStaticHtml(ColumnPO columnPO, SitePO sitePO, String parentColumnStoragePath, String h5ParentColumnStoragePath) {

        // 只有是列表、分页列表、频道封面的栏目,才查询
        ArrayList<String> columnTypeList = new ArrayList<>();
        columnTypeList.add(ColumnEnum.LIST.getType());
        columnTypeList.add(ColumnEnum.PAGE_LIST.getType());
        columnTypeList.add(ColumnEnum.CHANNLE_COVER.getType());
        if (columnTypeList.contains(columnPO.getType())) {
            // 1、生成栏目页列表页和文章列表页
            p_staticColumnToStatic(columnPO, sitePO, parentColumnStoragePath, h5ParentColumnStoragePath);
        }

        // 2、获取文章列表------生成文章页面
        // 生成文章, 类型查询栏目下的已发布的文章, 为图文咨询和公告
        QueryWrapper<ArticlePO> articlePOQueryWrapper = new QueryWrapper<>();
        articlePOQueryWrapper.eq("COLUMN_ID", columnPO.getId());
        articlePOQueryWrapper.eq("ARTICLE_STATUS", ArticleEnum.STATUS_YI_FA_BU.getValue());
        ArrayList<String> stringArrayList = new ArrayList<>();
        stringArrayList.add(ArticleEnum.TYPE_TU_WEN_ZI_XUN.getValue());
        stringArrayList.add(ArticleEnum.TYPE_GONG_GAO_ZI_XUN.getValue());
        // 类型为图文咨询和公告
        articlePOQueryWrapper.in("TYPE", stringArrayList);
        List<ArticlePO> articlePOList = articleService.list(articlePOQueryWrapper);
        // 3、获取栏目对应的文章模板----如果没有绑定模板就跳过
        QueryWrapper<ColumnArticleModelPO> columnArticleModelPOQueryWrapper = new QueryWrapper<>();
        columnArticleModelPOQueryWrapper.eq("COLUMN_ID", columnPO.getId());
        columnArticleModelPOQueryWrapper.eq("IS_RECOVERY", 0);
        ColumnArticleModelPO columnArticleModePO = columnArticleModelService.getOne(columnArticleModelPOQueryWrapper);
        if (ValidateUtil.isNullOrEmpty(columnArticleModePO)) return false;

        // pcTemplatePath = columnPO所绑定的文章模型中的模板的路径
        String pcTemplatePath = columnArticleModePO.getPcTemplateFilePath();
        String columnStoragePath = parentColumnStoragePath + File.separator + columnPO.getEncoded();
        String h5TemplatePath = null;
        String h5columnStoragePath = null;
        if (null != columnArticleModePO.getH5TemplateFilePath()) {
            h5TemplatePath = columnArticleModePO.getH5TemplateFilePath();
            h5columnStoragePath = h5ParentColumnStoragePath + File.separator + columnPO.getEncoded();
        }


        // 生成文章页面
        for (ArticlePO articlePO : articlePOList) {
            p_staticArticleToStatic(articlePO, sitePO, columnPO, pcTemplatePath, columnStoragePath, h5TemplatePath, h5columnStoragePath);
        }

        // 查询子栏目列表
        QueryWrapper<ColumnPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PARENT_ID", columnPO.getId());
        queryWrapper.eq("IS_RECOVERY", 0);
        queryWrapper.orderByDesc("SORT");
        queryWrapper.orderByAsc("ID");
        List<ColumnPO> columnPOList = columnService.list(queryWrapper);
        // 没有子栏目就不生成
        if (ValidateUtil.isNullOrEmpty(columnPOList)) return true;
        for (ColumnPO childColumnPO : columnPOList) {
            p_generateColumnAndArticleStaticHtml(childColumnPO, sitePO, columnStoragePath, h5columnStoragePath);
        }
        return true;
    }

    /**
     * 生成静态的栏目页面
     *
     * @param columnPO
     * @param sitePO
     * @param pcParentColumnStoragePath 父级栏目的静态文件存储路径，或者是站点的静态文件存储路径
     * @param h5parentColumnStoragePath 父级栏目的静态文件存储路径，或者是站点的静态文件存储路径
     * @return
     */
    boolean p_staticColumnToStatic(ColumnPO columnPO, SitePO sitePO, String pcParentColumnStoragePath, String h5parentColumnStoragePath) {

        // 站点信息
        HashMap<String, Object> siteMap = new HashMap<>();
        siteMap.put("seoKeywords", sitePO.getSeoKeywords());
        siteMap.put("seoTitle", sitePO.getSeoTitle());
        siteMap.put("seoDesc", sitePO.getSeoDesc());
        siteMap.put("logo", sitePO.getLogo());
        siteMap.put("dm", sitePO.getDomainUrl());
        siteMap.put("siteId", String.valueOf(sitePO.getId()));

        // 静态文件存储路径-----到pc
        // 模板变量 -》 map
        HashMap<String, Object> columnMap = new HashMap<>();

        // 栏目logo
        String logo = StringUtils.isNotEmpty(columnPO.getLogo()) ? columnPO.getLogo() : sitePO.getLogo();
        // seoTitle
        String seoTitle = StringUtils.isNotEmpty(columnPO.getSeoTitle()) ? columnPO.getSeoTitle() : sitePO.getSeoTitle();
        // seoKeywords
        String seoKeywords = StringUtils.isNotEmpty(columnPO.getSeoKeywords()) ? columnPO.getSeoKeywords() : sitePO.getSeoKeywords();
        // seoDesc
        String seoDesc = StringUtils.isNotEmpty(columnPO.getSeoDesc()) ? columnPO.getSeoDesc() : sitePO.getSeoDesc();

        columnMap.put("seoKeywords", seoKeywords);
        columnMap.put("seoTitle", seoTitle);
        columnMap.put("seoDesc", seoDesc);
        columnMap.put("logo", logo);

        // 判断栏目下是否有子栏目,有子栏目就生成栏目列表页面，没有子栏目就生成文章列表页面（PS：栏目列表页面，包含了文章列表页面）
        QueryWrapper<ColumnPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", columnPO.getId());
        queryWrapper.eq("is_recovery", 0);
        List<ColumnPO> childColumnPOList = columnService.list(queryWrapper);

        if (childColumnPOList != null && childColumnPOList.size() > 0) {
            for (ColumnPO childColumnPO : childColumnPOList) {
                int page = 1;
                int limit = 15;
                int total = 0;

                columnMap.put("title", childColumnPO.getName());
                columnMap.put("columnId", String.valueOf(childColumnPO.getId()));

                if (ColumnEnum.PAGE_LIST.getType().equals(columnPO.getType())) {
                    // 查询该栏目下总共有多少已发布文章
                    QueryWrapper<ArticlePO> articlePOQueryWrapper = new QueryWrapper<>();
                    articlePOQueryWrapper.eq("COLUMN_ID", childColumnPO.getId());
                    articlePOQueryWrapper.eq("ARTICLE_STATUS", ArticleEnum.STATUS_YI_FA_BU.getValue());
                    articlePOQueryWrapper.eq("IS_RECOVERY", 0);
                    total = articleService.count(articlePOQueryWrapper);

                    // 每页显示的条目数

                    if (total == 0) {
                        return false;
                    }

                    limit = childColumnPO.getPageLimit();
                    if (limit == 0) limit = 15;
                    page = (int) Math.ceil(total / limit);
                }

                for (int i = 1; i <= page; i++) {

                    // 获取栏目的模板文件存储路径
                    String pcTemplatePath = columnPO.getPcTemplatePath();
                    String h5TemplatePath = null;
                    if (null != columnPO.getH5TemplatePath()) {
                        h5TemplatePath = columnPO.getH5TemplatePath();
                    }
                    columnMap.put("pageCount", page);
                    columnMap.put("page", i);
                    columnMap.put("limit", limit);

                    // 获取栏目的静态文件存储信息
                    String pcStorageStaticPath = "";
                    String h5StorageStaticPath = "";
                    if (page == 1) {
                        pcStorageStaticPath = pcParentColumnStoragePath + childColumnPO.getEncodedXpath() + File.separator + "index.html";
                        h5StorageStaticPath = h5parentColumnStoragePath + childColumnPO.getEncodedXpath() + File.separator + "index.html";
                    } else {
                        pcStorageStaticPath = pcParentColumnStoragePath + childColumnPO.getEncodedXpath() + File.separator + "index_" + i + ".html";
                        h5StorageStaticPath = h5parentColumnStoragePath + childColumnPO.getEncodedXpath() + File.separator + "index_" + i + ".html";
                    }

                    // 生成静态页面

                    if (null != h5TemplatePath) {
                        Map<String, Object> mapHashMap = new HashMap<>();
                        columnMap.put("pageUrl", "/h5" + childColumnPO.getEncodedXpath());
                        mapHashMap.put("site", siteMap);
                        mapHashMap.put("column", columnMap);
                        mapHashMap.put("dm", sitePO.getDomainUrl());
                        mapHashMap.put("parentColumnId", columnPO.getId());
                        beetlStaticHtml.create(h5TemplatePath, h5StorageStaticPath, mapHashMap);
                    }
                    Map<String, Object> mapHashMap = new HashMap<>();
                    columnMap.put("pageUrl", childColumnPO.getEncodedXpath());
                    mapHashMap.put("site", siteMap);
                    mapHashMap.put("column", columnMap);
                    mapHashMap.put("dm", sitePO.getDomainUrl());
                    mapHashMap.put("parentColumnId", columnPO.getId());
                    beetlStaticHtml.create(pcTemplatePath, pcStorageStaticPath, mapHashMap);
                }
            }
        } else {
            // 生成文章列表页面
            if (columnPO.getType().equals(ColumnEnum.SITE_INDEX.getType())) {
                return true;
                // 没有子栏目那么看是否是顶级栏目，如果是顶级栏目就生成静态文章列表页面，如果不是就不生成。
            } else if (!columnPO.getParentId().equals(0L)) {
                return true;
            }

            // 没有子栏目，生成文章列表页面
            int page = 1;
            int limit = 15;
            int total = 0;
            if (ColumnEnum.PAGE_LIST.getType().equals(columnPO.getType())) {
                // 查询该栏目下总共有多少已发布文章
                QueryWrapper<ArticlePO> articlePOQueryWrapper = new QueryWrapper<>();
                articlePOQueryWrapper.eq("COLUMN_ID", columnPO.getId());
                articlePOQueryWrapper.eq("ARTICLE_STATUS", ArticleEnum.STATUS_YI_FA_BU.getValue());
                articlePOQueryWrapper.eq("IS_RECOVERY", 0);
                total = articleService.count(articlePOQueryWrapper);

                // 每页显示的条目数

                if (total == 0) {
                    return false;
                }

                limit = columnPO.getPageLimit();
                if (limit == 0) limit = 15;
                page = (int) Math.ceil(total / limit);
            }


            for (int i = 1; i <= page; i++) {

                // 获取栏目的模板文件存储路径
                String pcTemplatePath = columnPO.getPcTemplatePath();
                String h5TemplatePath = null;
                if (null != columnPO.getH5TemplatePath()) {
                    h5TemplatePath = columnPO.getH5TemplatePath();
                }

                columnMap.put("pageCount", page);
                columnMap.put("page", i);
                columnMap.put("limit", limit);
                columnMap.put("columnId", columnPO.getId());


                // 获取栏目的静态文件存储信息
                String pcStorageStaticPath = "";
                String h5StorageStaticPath = "";
                if (page == 1) {
                    pcStorageStaticPath = pcParentColumnStoragePath + File.separator + columnPO.getEncoded() + File.separator + "index.html";
                    h5StorageStaticPath = h5parentColumnStoragePath + File.separator + columnPO.getEncoded() + File.separator + "index.html";
                } else {
                    pcStorageStaticPath = pcParentColumnStoragePath + File.separator + columnPO.getEncoded() + File.separator + "index_" + i + ".html";
                    h5StorageStaticPath = h5parentColumnStoragePath + File.separator + columnPO.getEncoded() + File.separator + "index_" + i + ".html";
                }

                if (null != h5TemplatePath) {
                    Map<String, Object> mapHashMap = new HashMap<>();
                    columnMap.put("pageUrl", "/h5" + columnPO.getEncodedXpath());
                    mapHashMap.put("site", siteMap);
                    mapHashMap.put("column", columnMap);
                    mapHashMap.put("dm", sitePO.getDomainUrl());
                    beetlStaticHtml.create(h5TemplatePath, h5StorageStaticPath, mapHashMap);
                }
                // 生成静态页面
                Map<String, Object> mapHashMap = new HashMap<>();
                columnMap.put("pageUrl", columnPO.getEncodedXpath());
                mapHashMap.put("site", siteMap);
                mapHashMap.put("column", columnMap);
                mapHashMap.put("dm", sitePO.getDomainUrl());
                beetlStaticHtml.create(pcTemplatePath, pcStorageStaticPath, mapHashMap);
            }
            return true;
        }
        return true;
    }

    /**
     * 生成文章静态页面
     *
     * @param articlePO         文章信息
     * @param pcTemplatePath    模板路径
     * @param columnStoragePath 静态文件存储路径
     * @return
     */
    boolean p_staticArticleToStatic(ArticlePO articlePO, SitePO sitePO, ColumnPO columnPO, String pcTemplatePath, String columnStoragePath, String h5TemplatePath, String h5ColumnStoragePath) {

        // 获取文章信息
        QueryWrapper<ArticleExtendPO> articleExtendPOQueryWrapper = new QueryWrapper<>();
        articleExtendPOQueryWrapper.eq("ARTICLE_ID", articlePO.getId());
        ArticleExtendPO extendPO = extendService.getOne(articleExtendPOQueryWrapper);
        // 如果没有扩展表信息，就先不生成
        if (ValidateUtil.isNullOrEmpty(extendPO)) return true;
        String content = extendPO.getContent();
        String seoTitle = extendPO.getSeoTitle();
        String seoKeywords = extendPO.getSeoKeywords();
        String seoDesc = extendPO.getSeoDesc();

        // 2.2 模板路径(对应栏目中文章模型绑定的模板), 如果没有就跳过，在上文已经判断过了。

        // 2.3 生成的静态文件路径，站点id + html  + pc(或h5) + 栏目编码（如果有父级，需要拼上父级） + article + 文章id.html
        // 静态文件保存路径
        String articleStoragePath = columnStoragePath + File.separator + "article" + File.separator + articlePO.getId() + ".html";
        String h5ArticleStoragePath = h5ColumnStoragePath + File.separator + "article" + File.separator + articlePO.getId() + ".html";

        // 站点信息
        HashMap<String, Object> siteMap = new HashMap<>();
        siteMap.put("seoKeywords", sitePO.getSeoKeywords());
        siteMap.put("seoTitle", sitePO.getSeoTitle());
        siteMap.put("seoDesc", sitePO.getSeoDesc());
        siteMap.put("logo", sitePO.getLogo());
        siteMap.put("dm", sitePO.getDomainUrl());
        siteMap.put("siteId", String.valueOf(sitePO.getId()));

        // 栏目信息
        HashMap<String, Object> columnMap = new HashMap<>();
        columnMap.put("seoKeywords", columnPO.getSeoKeywords());
        columnMap.put("seoTitle", columnPO.getSeoTitle());
        columnMap.put("seoDesc", columnPO.getSeoDesc());
        columnMap.put("logo", columnPO.getLogo());
        columnMap.put("title", columnPO.getName());
        columnMap.put("columnId", String.valueOf(columnPO.getId()));

        // 文章信息
        HashMap<String, Object> articleMap = new HashMap<>();
        articleMap.put("content", content);
        articleMap.put("seoTitle", seoTitle);
        articleMap.put("seoKeywords", seoKeywords);
        articleMap.put("title", articlePO.getTitle());
        articleMap.put("seoDesc", seoDesc);
        articleMap.put("articleId", articlePO.getId());


        Map<String, Object> mapHashMap = new HashMap<>();
        mapHashMap.put("site", siteMap);
        mapHashMap.put("column", columnMap);
        mapHashMap.put("article", articleMap);
        mapHashMap.put("dm", sitePO.getDomainUrl());

        // 3. 生成静态页面
        beetlStaticHtml.create(pcTemplatePath, articleStoragePath, mapHashMap);
        if (null != h5TemplatePath) {
            beetlStaticHtml.create(h5TemplatePath, h5ArticleStoragePath, mapHashMap);
        }

        return true;
    }


    /**
     * 静态化站点首页
     *
     * @return
     */
    Boolean p_staticIndexToStatic(SitePO sitePO) {

        // 模板变量 -》 map
        HashMap<String, Object> map = new HashMap<>();

        // 关键字
        String seoKeywords = sitePO.getSeoKeywords();
        // 标题
        String seoTitle = sitePO.getSeoTitle();
        // 描述
        String seoDesc = sitePO.getSeoDesc();
        // logo路径
        String logo = sitePO.getLogo();

        // 首先从中间表中查出站点对应的顶级栏目ID
        QueryWrapper<SiteColumnPO> siteColumnPOQueryWrapper = new QueryWrapper<>();
        siteColumnPOQueryWrapper.eq("SITE_ID", sitePO.getId());
        List<SiteColumnPO> list = siteColumnService.list(siteColumnPOQueryWrapper);
        ArrayList<Long> columnIdList = new ArrayList<>();
        if (!ValidateUtil.isNullOrEmpty(list)) {
            for (SiteColumnPO siteColumnPO : list) {
                columnIdList.add(siteColumnPO.getColumnId());
            }
        } else {
            // 栏目不存在
            this.errorMessageMap.put("isError", "1");
            this.errorMessageMap.put("msg", "未配置站点首页, 请先添加站点首页类型的栏目");
            return false;
        }

        // 站点下的顶级栏目，且类型是站点首页的栏目，获取模板路径
        QueryWrapper<ColumnPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("ID", columnIdList);
        queryWrapper.eq("IS_RECOVERY", 0);
        queryWrapper.eq("TYPE", ColumnEnum.SITE_INDEX.getType());
        queryWrapper.orderByDesc("SORT");
        queryWrapper.orderByAsc("ID");
        ColumnPO columnPO = columnService.getOne(queryWrapper, false);

        String pcTemplatePath = null;
        String h5TemplatePath = null;
        if (!ValidateUtil.isNullOrEmpty(columnPO)) {
            pcTemplatePath = columnPO.getPcTemplatePath();
            pcSiteTemplatePath = pcTemplatePath;
            if (null != columnPO.getH5TemplatePath()) {
                h5TemplatePath = columnPO.getH5TemplatePath();
                h5SiteTemplatePath = h5TemplatePath;
            }
        } else {
            // 栏目不存在
            this.errorMessageMap.put("isError", "1");
            this.errorMessageMap.put("msg", "未配置站点首页, 请先添加站点首页类型的栏目");
            return false;
        }

        // 判断模板文件是否存在
        if (!FileUtil.exist(pcTemplatePath) && !FileUtil.exist(h5TemplatePath)) {
            // 栏目不存在
            this.errorMessageMap.put("isError", "1");
            this.errorMessageMap.put("msg", "模板文件不存在, 请先配置模板");
            return false;
        }

        // 静态文件保存路径
        String storageStaticPath = siteService.getStorageStaticPath(sitePO.getId());

        String pcStorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "index.html";
        String h5StorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "h5" + File.separator + "index.html";

        map.put("seoKeywords", seoKeywords);
        map.put("seoTitle", seoTitle);
        map.put("seoDesc", seoDesc);
        map.put("logo", logo);
        map.put("siteId", String.valueOf(sitePO.getId()));
        map.put("dm", sitePO.getDomainUrl());

        Map<String, Object> stringMapHashMap = new HashMap<>();
        stringMapHashMap.put("site", map);

        try {
            // 生成pc端静态页面
            beetlStaticHtml.create(pcTemplatePath, pcStorageStaticPath, stringMapHashMap);
            // 生成h5端静态页面
            if (null != h5TemplatePath) {
                beetlStaticHtml.create(h5TemplatePath, h5StorageStaticPath, stringMapHashMap);
            }
        }catch (Exception e) {
            e.printStackTrace();
            // 栏目不存在
            this.errorMessageMap.put("isError", "1");
            this.errorMessageMap.put("msg", "静态文件生成失败:" + e.getMessage());
            return false;
        }

        return true;
    }


    @ApiOperation(value = "静态化站点首页")
    @GetMapping("/static-site-home-html")
    public R staticSiteHome(@ApiParam(value = "站点id", required = true, example = "123456789") @RequestParam(required = false) Long siteId) {
        // 接收参数
        if (siteId == null || !ValidateUtil.Number(siteId) || siteId <= 0)
            return R.failureRequestParam().msg("站点id不能为空");

        // 查询站点信息
        SitePO sitePO = siteService.getById(siteId);
        if (ValidateUtil.isNullOrEmpty(sitePO)) return R.resultCodeMsg(ResultCodeMsgEnum.DATA_NOT_EXIST);

        QueryWrapper<StaticLogPO> staticLogPOQueryWrapper = new QueryWrapper<>();
        staticLogPOQueryWrapper.eq("SITE_ID", siteId);
        staticLogPOQueryWrapper.eq("STATUS", StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        staticLogPOQueryWrapper.eq("STATIC_TYPE", StaticHtmlTypeEnum.HOME.getValue());
        StaticLogPO staticLogPO = staticLogService.getOne(staticLogPOQueryWrapper, false);
        if (null != staticLogPO && null != staticLogPO.getId()) {
            return R.failure().msg("静态化任务正在进行,请稍后再试!");
        }

        // 将静态化日志设置为进行中
        StaticLogPO logPO = new StaticLogPO();
        logPO.setSiteId(siteId);
        // 进行中
        logPO.setStatus(StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        // 站点首页静态化
        logPO.setStaticType(StaticHtmlTypeEnum.HOME.getValue());
        boolean save = staticLogService.save(logPO);

        // 生成站点首页
        Boolean siteResult = p_staticIndexToStatic(sitePO);
        if (!siteResult) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            return R.failure().msg(this.errorMessageMap.get("msg"));
        }

        // 站点的静态文件存储路径
        String storageStaticPath = siteService.getStorageStaticPath(sitePO.getId());

        // 拷贝站点的资源文件到静态文件路径中
        boolean storage = this.p_copyResources(sitePO, storageStaticPath);

        if (!storage) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            return R.failure().msg("静态资源拷贝失败");
        }

        // 如果前面的操作成功，则生成完成以后将日志信息设置为完成
        if (save) {
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.YI_WAN_CHENG.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
        }

        return R.success().msg("静态化站点首页");
    }


    @ApiOperation(value = "静态化栏目页面")
    @GetMapping("/static-column-html")
    public R staticColumnHtml(@ApiParam(value = "站点id", required = true, example = "123456789") @RequestParam(required = false) Long siteId,
                              @ApiParam(value = "栏目id", required = true, example = "123456789") @RequestParam(required = false) Long columnId) {
        // 参数校验
        if (siteId == null || !ValidateUtil.Number(siteId) || siteId <= 0)
            return R.failureRequestParam().msg("站点id不能为空");

        // 参数校验
        if (columnId == null || !ValidateUtil.Number(columnId) || columnId <= 0)
            return R.failureRequestParam().msg("栏目id不能为空");

        // 查询站点信息
        SitePO sitePO = siteService.getById(siteId);
        if (ValidateUtil.isNullOrEmpty(sitePO)) return R.resultCodeMsg(ResultCodeMsgEnum.DATA_NOT_EXIST);

        // 查询栏目信息
        QueryWrapper<ColumnPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ID", columnId);
        queryWrapper.eq("IS_RECOVERY", 0);
        ColumnPO columnPO = columnService.getOne(queryWrapper, false);
        // 如果栏目为空，直接返回
        if (ValidateUtil.isNullOrEmpty(columnPO)) return R.success();

        QueryWrapper<StaticLogPO> staticLogPOQueryWrapper = new QueryWrapper<>();
        staticLogPOQueryWrapper.eq("SITE_ID", siteId);
        staticLogPOQueryWrapper.eq("COLUMN_ID", columnId);
        staticLogPOQueryWrapper.eq("STATUS", StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        staticLogPOQueryWrapper.eq("STATIC_TYPE", StaticHtmlTypeEnum.COLUMN.getValue());
        StaticLogPO staticLogPO = staticLogService.getOne(staticLogPOQueryWrapper, false);
        if (null != staticLogPO && null != staticLogPO.getId()) {
            return R.failure().msg("静态化任务正在进行,请稍后再试!");
        }

        // 将静态化日志设置为进行中
        StaticLogPO logPO = new StaticLogPO();
        // 站点id和栏目id
        logPO.setSiteId(siteId);
        logPO.setColumnId(columnId);
        // 进行中
        logPO.setStatus(StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        // 栏目静态化
        logPO.setStaticType(StaticHtmlTypeEnum.COLUMN.getValue());
        boolean save = staticLogService.save(logPO);

        // 如果不为空就要准备生成--------站点的静态文件存储路径
        String storageStaticPath = siteService.getStorageStaticPath(sitePO.getId());
        // TODO::H5的静态化暂时没有生成
        // 静态文件存储路径-----到pc
        String pcStorageStaticPath = storageStaticPath + File.separator + "pc";
        String h5StorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "h5";
        boolean result;

        // 生成栏目页，子栏目和栏目下的文章页面
        result = p_generateColumnAndArticleStaticHtml(columnPO, sitePO, pcStorageStaticPath, h5StorageStaticPath);

        if (!result) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            R.failure().msg("失败");
        }

        // 如果前面的操作成功，则生成完成以后将日志信息设置为完成
        if (save) {
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.YI_WAN_CHENG.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
        }

        return R.success().msg("成功");
    }

    @ApiOperation(value = "静态化文章页面")
    @GetMapping("/static-article-html")
    public R staticArticleHtml(@ApiParam(value = "站点id", required = true, example = "123456789") @RequestParam(required = false) Long siteId,
                               @ApiParam(value = "栏目id", required = true, example = "123456789") @RequestParam(required = false) Long columnId,
                               @ApiParam(value = "文章id", required = true, example = "123456789") @RequestParam(required = false) Long articleId) {
        // 参数校验
        if (siteId == null || !ValidateUtil.Number(siteId) || siteId <= 0)
            return R.failureRequestParam().msg("站点id不能为空");

        if (columnId == null || !ValidateUtil.Number(columnId) || columnId <= 0)
            return R.failureRequestParam().msg("栏目id不能为空");

        if (articleId == null || !ValidateUtil.Number(articleId) || articleId <= 0)
            return R.failureRequestParam().msg("文章id不能为空");

        // 查询站点信息
        SitePO sitePO = siteService.getById(siteId);
        if (ValidateUtil.isNullOrEmpty(sitePO)) return R.resultCodeMsg(ResultCodeMsgEnum.DATA_NOT_EXIST);

        // 查询栏目信息
        ColumnPO columnPO = columnService.getById(columnId);
        if (ValidateUtil.isNullOrEmpty(columnPO)) return R.resultCodeMsg(ResultCodeMsgEnum.DATA_NOT_EXIST);

        // 查询文章信息
        ArticlePO articlePO = articleService.getById(articleId);

        QueryWrapper<StaticLogPO> staticLogPOQueryWrapper = new QueryWrapper<>();
        staticLogPOQueryWrapper.eq("SITE_ID", siteId);
        staticLogPOQueryWrapper.eq("COLUMN_ID", columnId);
        staticLogPOQueryWrapper.eq("ARTICLE_ID", articleId);
        staticLogPOQueryWrapper.eq("STATUS", StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        staticLogPOQueryWrapper.eq("STATIC_TYPE", StaticHtmlTypeEnum.ARTICLE.getValue());
        StaticLogPO staticLogPO = staticLogService.getOne(staticLogPOQueryWrapper, false);
        if (null != staticLogPO && null != staticLogPO.getId()) {
            return R.failure().msg(articlePO.getType() + ":静态化任务正在进行,请稍后再试!");
        }

        // 获取栏目对应的文章模板,如果没有绑定模板则返回错误
        QueryWrapper<ColumnArticleModelPO> columnArticleModelPOQueryWrapper = new QueryWrapper<>();
        columnArticleModelPOQueryWrapper.eq("COLUMN_ID", columnPO.getId());
        columnArticleModelPOQueryWrapper.eq("IS_RECOVERY", 0);
        ColumnArticleModelPO columnArticleModePO = columnArticleModelService.getOne(columnArticleModelPOQueryWrapper);
        if (ValidateUtil.isNullOrEmpty(columnArticleModePO)) return R.failure().msg("文章模板未绑定");

        // 模板路径
        String pcTemplatePath = columnArticleModePO.getPcTemplateFilePath();
        String h5TemplatePath = columnArticleModePO.getH5TemplateFilePath();

        // 静态文件保存路径
        String storageStaticPath = siteService.getStorageStaticPath(sitePO.getId());
        String pcStorageStaticPath = storageStaticPath + File.separator + "pc";
        String pcColumnStoragePath = pcStorageStaticPath + File.separator + columnPO.getEncodedXpath();
        String h5StorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "h5";
        String h5ColumnStoragePath = h5StorageStaticPath + File.separator + columnPO.getEncodedXpath();


        // 将静态化日志设置为进行中
        StaticLogPO logPO = new StaticLogPO();
        // 站点id和栏目id
        logPO.setSiteId(siteId);
        logPO.setColumnId(columnId);
        logPO.setArticleId(articleId);
        // 进行中
        logPO.setStatus(StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
        // 栏目静态化
        logPO.setStaticType(StaticHtmlTypeEnum.ARTICLE.getValue());
        boolean save = staticLogService.save(logPO);

        // 生成文章页面
        boolean staticArticle = p_staticArticleToStatic(articlePO, sitePO, columnPO, pcTemplatePath, pcColumnStoragePath, h5TemplatePath, h5ColumnStoragePath);

        if (!staticArticle) {
            // 日志设置为失败
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
            return R.failure().msg("失败");
        }
        // 如果前面的操作成功，则生成完成以后将日志信息设置为完成
        if (save) {
            StaticLogPO staticLog = new StaticLogPO();
            staticLog.setStatus(StaticHtmlStatusEnum.YI_WAN_CHENG.getValue());
            staticLog.setId(logPO.getId());
            staticLogService.updateById(staticLog);
        }
        return R.success().msg("成功");

    }


    @ApiOperation(value = "批量静态化文章页面")
    @GetMapping("/static-batch-article-html")
    public R staticBatchArticleHtml(@ApiParam(value = "站点id", required = true, example = "123456789") @RequestParam(required = false) Long siteId,
                                    @ApiParam(value = "文章ids", required = true, example = "123456789") @RequestParam(required = false) String articleIds) {
        // 参数校验
        if (siteId == null || !ValidateUtil.Number(siteId) || siteId <= 0)
            return R.failureRequestParam().msg("站点id不能为空");

        if (articleIds == null || StringUtils.isEmpty(articleIds))
            return R.failureRequestParam().msg("文章ids不能为空");

        // 查询站点信息
        SitePO sitePO = siteService.getById(siteId);
        if (ValidateUtil.isNullOrEmpty(sitePO)) return R.resultCodeMsg(ResultCodeMsgEnum.DATA_NOT_EXIST);

        String[] split = articleIds.split(",");
        ArrayList<Long> articleIdList = new ArrayList<>();
        for (String s : split) {
            articleIdList.add(Long.parseLong(s));
        }

        // 查询文章信息
        List<ArticlePO> articlePOList = articleService.listByIds(articleIdList);

        if (null == articlePOList && articlePOList.size() == 0) {
            return R.failure().msg("文章不存在或已被删除");
        }

        for (ArticlePO articlePO : articlePOList) {
            // 查询栏目信息
            ColumnPO columnPO = columnService.getById(articlePO.getColumnId());
            if (ValidateUtil.isNullOrEmpty(columnPO)) return R.resultCodeMsg(ResultCodeMsgEnum.DATA_NOT_EXIST);

            QueryWrapper<StaticLogPO> staticLogPOQueryWrapper = new QueryWrapper<>();
            staticLogPOQueryWrapper.eq("SITE_ID", siteId);
            staticLogPOQueryWrapper.eq("COLUMN_ID", articlePO.getColumnId());
            staticLogPOQueryWrapper.eq("ARTICLE_ID", articlePO.getId());
            staticLogPOQueryWrapper.eq("STATUS", StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
            staticLogPOQueryWrapper.eq("STATIC_TYPE", StaticHtmlTypeEnum.ARTICLE.getValue());
            StaticLogPO staticLogPO = staticLogService.getOne(staticLogPOQueryWrapper, false);
            if (null != staticLogPO && null != staticLogPO.getId()) {
                return R.failure().msg(articlePO.getType() + ":静态化任务正在进行,请稍后再试!");
            }

            // 获取栏目对应的文章模板,如果没有绑定模板则返回错误
            QueryWrapper<ColumnArticleModelPO> columnArticleModelPOQueryWrapper = new QueryWrapper<>();
            columnArticleModelPOQueryWrapper.eq("COLUMN_ID", columnPO.getId());
            columnArticleModelPOQueryWrapper.eq("IS_RECOVERY", 0);
            ColumnArticleModelPO columnArticleModePO = columnArticleModelService.getOne(columnArticleModelPOQueryWrapper);
            if (ValidateUtil.isNullOrEmpty(columnArticleModePO)) return R.failure().msg("文章模板未绑定");

            // 模板路径
            String pcTemplatePath = columnArticleModePO.getPcTemplateFilePath();
            String h5TemplatePath = columnArticleModePO.getH5TemplateFilePath();

            // 静态文件保存路径
            String storageStaticPath = siteService.getStorageStaticPath(sitePO.getId());
            String pcStorageStaticPath = storageStaticPath + File.separator + "pc";
            String pcColumnStoragePath = pcStorageStaticPath + File.separator + columnPO.getEncodedXpath();
            String h5StorageStaticPath = storageStaticPath + File.separator + "pc" + File.separator + "h5";
            String h5ColumnStoragePath = h5StorageStaticPath + File.separator + columnPO.getEncodedXpath();

            // 将静态化日志设置为进行中
            StaticLogPO logPO = new StaticLogPO();
            // 站点id和栏目id
            logPO.setSiteId(siteId);
            logPO.setColumnId(articlePO.getColumnId());
            logPO.setArticleId(articlePO.getId());
            // 进行中
            logPO.setStatus(StaticHtmlStatusEnum.JIN_XING_ZHONG.getValue());
            // 文章静态化
            logPO.setStaticType(StaticHtmlTypeEnum.ARTICLE.getValue());
            boolean save = staticLogService.save(logPO);

            // 生成文章页面
            boolean staticArticle = p_staticArticleToStatic(articlePO, sitePO, columnPO, pcTemplatePath, pcColumnStoragePath, h5TemplatePath, h5ColumnStoragePath);

            if (!staticArticle) {
                // 日志设置为失败
                StaticLogPO staticLog = new StaticLogPO();
                staticLog.setStatus(StaticHtmlStatusEnum.SHI_BAI.getValue());
                staticLog.setId(logPO.getId());
                staticLogService.updateById(staticLog);
                return R.failure().msg("静态化[" + articlePO.getTitle() + "]失败");
            }
            // 如果前面的操作成功，则生成完成以后将日志信息设置为完成
            if (save) {
                StaticLogPO staticLog = new StaticLogPO();
                staticLog.setStatus(StaticHtmlStatusEnum.YI_WAN_CHENG.getValue());
                staticLog.setId(logPO.getId());
                staticLogService.updateById(staticLog);
            }
        }
        return R.success().msg("成功");
    }

}
